<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>访客申请-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			<div class="weui-header bg-blue"> 
				<div class="weui-header-left"> <a onclick="back()" class="icon icon-109 f-white">返回</a></div>
				<h1 class="weui-header-title">访客申请</h1>
			</div>
	        <div class="weui_cells mt0">
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">申请人</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<p>${user.parent.studentName }的${user.parent.relation }</p>
					</div>
				</div>
			</div>
	        
			<div class="weui_cells weui_cells_form">
				<div class="weui_cells_title">来访时间和事由</div>
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">来访时间</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
                		<input id="visitStartDate" name="visitStartDate" class="weui_input" placeholder="请选择来访时间"/>
            		</div>
	            </div>
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">离开时间</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <input id="visitEndDate" name="visitEndDate" class="weui_input" placeholder="请选择离开时间"/>
	                </div>
	            </div>
	            <div class="weui_cell xtbg-add-list-title">
					<div class="weui_cell_bd weui_cell_primary">
						<p class="f14">来访事由</p>
					</div>
				</div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <textarea id="visitPurpose" name="visitPurpose" class="weui_textarea" placeholder="请输入来访原因" rows="3"></textarea>
	                </div>
	            </div>
	         </div>
	         <div class="weui_cells weui_cells_form">
	         	<div class="weui_cells_title">访客信息</div>
	            <div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">访客姓名</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
                		<input id="visitorName" name="visitorName" type="text" class="weui_input" placeholder="请输入访客姓名"/>
            		</div>
	            </div>
	            <div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">访客性别</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
                		<input id="gender" name="gender" type="text" class="weui_input" placeholder="请选择访客性别"/>
            		</div>
	            </div>
	            <div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label">访客电话</label>
					</div>
	                <div class="weui_cell_bd weui_cell_primary">
                		<input id="phoneNo" name="phoneNo" type="number" class="weui_input" placeholder="请输入访客电话"/>
            		</div>
	            </div>
	        </div>
	       <div class="weui_btn_area">
		        <a href="javascript:" onclick="submit()" class="weui_btn bg-blue">确认提交</a>
		    </div>
		</div>
	</div>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script src="<%=basePath %>/js/picker.js"></script>
<script src="<%=basePath %>/js/select.js"></script>
<script type="text/javascript">
	$(function() {
		$("#visitStartDate").datetimePicker({title:"选择来访时间"});
		$("#visitEndDate").datetimePicker({title:"选择离开时间"});
		$("#gender").select({
	        title: "选择访客性别",
	        closeText:'完成',
	        items: [
	        	{title: "男",value: 1},
	        	{title: "女",value: 2}
	        ]
		});
	})
	
	function submit() {
		var visitStartDate = $("#visitStartDate").val();
		if(visitStartDate.length == 0) {
			$.alert("请选择来访时间!","");
			return;
		}
		var visitEndDate = $("#visitEndDate").val();
		if(visitEndDate.length == 0) {
			$.alert("请选择离开时间!","");
			return;
		}
		var visitPurpose = $("#visitPurpose").val();
		if(visitPurpose.length == 0) {
			$.alert("请输入来访事由!","");
			return;
		}
		var visitorName = $("#visitorName").val();
		if(visitorName.length == 0) {
			$.alert("请输入访客姓名!","");
			return;
		}
		var gender = $("#gender").attr("data-values");
		if(!gender) {
			$.alert("请选择访客性别!","");
			return;
		}
		var phoneNo = $("#phoneNo").val();
		if(phoneNo.length == 0) {
			$.alert("请输入访客电话!","");
			return;
		}
		$.ajax({
			url: basePath + '/xs/visitor/appointment/apply/submit',
			type: 'post',
			dataType: 'json',
			data: {
				visitStartDate: visitStartDate,
				visitEndDate: visitEndDate,
				visitPurpose: visitPurpose,
				visitorName: visitorName,
				gender: gender,
				phoneNo: phoneNo
			},
			success: function(data) {
				if (data.code == '000') {
					$.toast("提交成功！");
					setTimeout(function() {
	   					back();
	   				}, 1000);
				} else {
					$.toptips(data.msg);
				}
			},
            error: function(xhr, type){
            	$.toptips("系统异常");
            }
		});
	}
	
</script>
</body>
</html>